Imports Clo = Enhancements.Core.Logging
Imports Fun = Enhancements.Basic.Expressions.Functions
Imports Gen = System.Collections.Generic
Imports Glo = System.Globalization
Imports Lev = Enhancements.Basic.Expressions.Levels
Imports Sys = System
Imports Val = Enhancements.Basic.Expressions.Values

Namespace Enhancements.Basic.Expressions
    ''' <summary>Represents a token extracted from an expression which nature's was not possible to determine or have not yet been determined.</summary>
    <Serializable(), DebuggerStepThrough()> _
    Public NotInheritable Class Undetermined
        Inherits Token

        Friend Sub New(ByVal _expression As System.String, ByVal _expressionBeginIndex As Sys.Int32, ByVal _expressionEndIndex As Sys.Int32)
            MyBase.New(_expression, _expressionBeginIndex, _expressionEndIndex)
        End Sub

        ''' <summary>Returns the token's representation.</summary>
        ''' <returns> </returns>
        Public Overrides Function ToRepresentation() As System.String
            Dim _returnValue As System.String = ExpressionPart

            Return _returnValue
        End Function

        ''' <exception cref="IsNullException"> </exception>
        ''' <exception cref="IsListFilledNotException"> </exception>
        Friend Shared Function ___PutInArray(ByVal _tokens As Gen.List(Of Token)) As Undetermined()
            _tokens.IsListFilled("_tokens", True)

            Dim _returnValueList As Gen.List(Of Undetermined) = New Gen.List(Of Undetermined)()
            For Each _token As Token In _tokens
                If _token.IsOfType("_token", GetType(Undetermined), False) Then
                    _returnValueList.Add(CType(_token, Undetermined))
                End If
            Next _token

            Return _returnValueList.ToArray()
        End Function

        ''' <exception cref="IsNullException"> </exception>
        ''' <exception cref="IsListFilledNotException"> </exception>
        Friend Shared Sub ___AppendNewToEndOrReplaceLastWithNew(ByVal _tokens As Gen.List(Of Token), ByVal _expression As System.String, ByVal _expressionBeginIndex As Sys.Int32, ByVal _expressionEndIndex As Sys.Int32)
            _tokens.IsListFilled("_tokens", True)

            If _tokens.Count.IsInRange("_tokens.Count", 1, Sys.Int32.MaxValue, False) Then
                If _tokens(_tokens.Count - 1).IsOfType("_tokens(_tokens.Count - 1)", GetType(Undetermined), False) Then
                    Dim _tokenToRemove As Undetermined = CType(_tokens.Last(), Undetermined)
                    Dim _tokenToAdd As Undetermined = New Undetermined(_tokenToRemove.Expression, _tokenToRemove.ExpressionBeginIndex, _expressionEndIndex)
                    _tokens.Remove(_tokenToRemove)
                    _tokens.Add(_tokenToAdd)
                Else
                    _tokens.Add(New Undetermined(_expression, _expressionBeginIndex, _expressionEndIndex))
                End If
            Else
                _tokens.Add(New Undetermined(_expression, _expressionBeginIndex, _expressionEndIndex))
            End If
        End Sub

    End Class
End Namespace
